package com.cn.pw.frame.service;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.cn.pw.frame.dao.UserDao;
import com.cn.pw.frame.dao.entity.User;

public class UserDetailServiceImpl implements UserDetailsService {

	private static final Logger logger = Logger
			.getLogger(UserDetailServiceImpl.class);

	private UserDao userDao;

	@Override
	public UserDetails loadUserByUsername(String userName)
			throws UsernameNotFoundException, DataAccessException {

		if (userName == null) {
			logger.error("userName is null");
		}

		User user = userDao.findUserbyName(userName);

		if (user == null) {
			logger.error(userName + " is not exist",
					new UsernameNotFoundException(userName + " is not exist"));
		}
	
		return user;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
